package com.power.leopard.remote.provider.process.filter;

import com.power.leopard.constants.Constants;
import com.power.leopard.remote.common.domain.InvocationRequest;
import com.power.leopard.remote.common.domain.InvocationResponse;
import com.power.leopard.remote.common.process.ServiceInvocationFilter;
import com.power.leopard.remote.common.process.ServiceInvocationHandler;
import com.power.leopard.remote.provider.domain.ProviderChannel;
import com.power.leopard.remote.provider.domain.ProviderContext;

public class WriteResponseProcessFilter implements ServiceInvocationFilter<ProviderContext> {

	public InvocationResponse invoke(ServiceInvocationHandler handler, ProviderContext providerContext) throws Throwable {
		ProviderChannel channel = providerContext.getChannel();
		InvocationRequest request = providerContext.getRequest();
		InvocationResponse response = handler.handle(providerContext);

		if (request.getCallType() == Constants.CALLTYPE_REPLY) {
			channel.write(response);
		}

		if (request.getMessageType() == Constants.MESSAGE_TYPE_SERVICE) {

		}
		return response;

	}

}
